2020-2021 Sunseeker Telemetry and Lighting System
ref_a_ex1_ctlADC12B.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 //
34 // REFA - ADC12B, Using REFA Module to control Internal Reference
35 //
36 // This example shows how to configure the internal reference of REFA module
37 // using the REFACTL0 control register. The ADC12B uses the internal 2.5V
38 // reference and performs a single conversion on channel A0. The conversion
39 // results are stored in ADC12BMEM0. Test by applying a voltage to channel A0,
40 // then setting and running to a break point at the "__no_operation()"
41 // instruction. To view the conversion results, open an ADC12B register window
42 // in debugger and view the contents of ADC12BMEM0.
43 //
44 // NOTE: REFAMSTR bit in REFACTL0 regsiter is by default set to 1. This allows
45 // the REFACTL0 control regsiters to configure the reference setting. The
46 // legacy ADC12B reference control bits ADC12REFAON, ADC12REFA2_5, ADC12BTCOFF
47 // and ADC12BREFAOUT are dont care in this case.
48 //
49 // MSP430FR5969
50 // -----------------
51 // /|\| |
52 // | | |
53 // --|RST |
54 // | |
55 // | P1.0/A0|<- Vin
56 // | |
57 //
58 //
59 // This example uses the following peripherals and I/O signals. You must
60 // review these and change as needed for your own board:
61 // - REFA peripheral
62 // - ADC12B peripheral
63 // - GPIO Port peripheral
64 // - A0
65 //
66 // This example uses the following interrupt handlers. To use this example
67 // in your own application you must add these interrupt handlers to your
68 // vector table.
69 // - None.
70 //
71 //******************************************************************************
72 #include "driverlib.h"
73 
74 void main (void)
75 {
76  //Stop watchdog timer
77  WDT_A_hold(WDT_A_BASE);
78 
79  //Set P1.0 as Ternary Module Function Output.
80  /*
81 
82  * Select Port 1
83  * Set Pin 0 to output Ternary Module Function, (A0, C0, VREFA-, VeREFA-).
84  */
85  GPIO_setAsPeripheralModuleFunctionOutputPin(
86  GPIO_PORT_P1,
87  GPIO_PIN0,
88  GPIO_TERNARY_MODULE_FUNCTION
89  );
90 
91  /*
92  * Disable the GPIO power-on default high-impedance mode to activate
93  * previously configured port settings
94  */
95  PMM_unlockLPM5();
96 
97  //If ref generator busy, WAIT
98  while (Ref_A_isRefGenBusy(REF_A_BASE)) ;
99  //Select internal ref = 2.5V
100  Ref_A_setReferenceVoltage(REF_A_BASE,
101  REF_A_VREF2_5V);
102  //Internal Reference ON
103  Ref_A_enableReferenceVoltage(REF_A_BASE);
104 
105  //Delay (~75us) for Ref to settle
106  __delay_cycles(75);
107 
108  //Initialize the ADC12 Module
109  /*
110  * Base address of ADC12 Module
111  * Use internal ADC12 bit as sample/hold signal to start conversion
112  * USE MODOSC 5MHZ Digital Oscillator as clock source
113  * Use default clock divider/pre-divider of 1
114  * Map to internal channel 0
115  */
116  ADC12_B_initParam initParam = {0};
117  initParam.sampleHoldSignalSourceSelect = ADC12_B_SAMPLEHOLDSOURCE_SC;
118  initParam.clockSourceSelect = ADC12_B_CLOCKSOURCE_ADC12OSC;
119  initParam.clockSourceDivider = ADC12_B_CLOCKDIVIDER_1;
120  initParam.clockSourcePredivider = ADC12_B_CLOCKPREDIVIDER__1;
121  initParam.internalChannelMap = ADC12_B_MAPINTCH0;
122  ADC12_B_init(ADC12_B_BASE, &initParam);
123 
124  //Enable the ADC12B module
125  ADC12_B_enable(ADC12_B_BASE);
126 
127  /*
128  * Base address of ADC12B Module
129  * For memory buffers 0-7 sample/hold for 64 clock cycles
130  * For memory buffers 8-15 sample/hold for 4 clock cycles (default)
131  * Disable Multiple Sampling
132  */
133  ADC12_B_setupSamplingTimer(ADC12_B_BASE,
134  ADC12_B_CYCLEHOLD_64_CYCLES,
135  ADC12_B_CYCLEHOLD_4_CYCLES,
136  ADC12_B_MULTIPLESAMPLESDISABLE);
137 
138  //Configure Memory Buffer
139  /*
140  * Base address of the ADC12B Module
141  * Configure memory buffer 0
142  * Map input A0 to memory buffer 0
143  * Vref+ = Vref+ (INT)
144  * Vref- = AVss
145  */
146  ADC12_B_configureMemoryParam configureMemoryParam = {0};
147  configureMemoryParam.memoryBufferControlIndex = ADC12_B_MEMORY_0;
148  configureMemoryParam.inputSourceSelect = ADC12_B_INPUT_A0;
149  configureMemoryParam.refVoltageSourceSelect = ADC12_B_VREFPOS_INTBUF_VREFNEG_VSS;
150  configureMemoryParam.endOfSequence = ADC12_B_NOTENDOFSEQUENCE;
151  configureMemoryParam.windowComparatorSelect = ADC12_B_WINDOW_COMPARATOR_DISABLE;
152  configureMemoryParam.differentialModeSelect = ADC12_B_DIFFERENTIAL_MODE_DISABLE;
153  ADC12_B_configureMemory(ADC12_B_BASE, &configureMemoryParam);
154 
155  while (1)
156  {
157  //Enable/Start sampling and conversion
158  /*
159  * Base address of ADC12B Module
160  * Start the conversion into memory buffer 0
161  * Use the single-channel, single-conversion mode
162  */
163  ADC12_B_startConversion(ADC12_B_BASE,
164  ADC12_B_MEMORY_0,
165  ADC12_B_SINGLECHANNEL);
166 
167  //Poll for interrupt on memory buffer 0
168  while (!ADC12_B_getInterruptStatus(ADC12_B_BASE,
169  0,
170  ADC12IFG0));
171 
172  //SET BREAKPOINT HERE
173  __no_operation();
174  }
175 }
176 
__no_operation()
__delay_cycles(500000)
void main(void)